Subject: Re: need help with serial communication using c++
Date: Wed, 20 Mar 1996 21:21:12 -0600
Organization: customer of Internet America
Message-ID: <3150CB28.1CE3@airmail.net>
References: <DoLBFr.Hvp@seas.ucla.edu>
NNTP-Posting-Host: dal17-30.ppp.iadfw.net
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 2.0GoldB1 (Win95; I)
Daniel D Shin wrote:
>
> Can someone out there help me how to write serial communication program using c language? Specifically, I need to translate a qbasic program into c. The basi
>
> OPEN "COM1:9600,e,7,1,CS,DS" FOR RANDOM AS #1
> PRINT #1, "CH",cn
> INPUT #1, dummy
> CLOSE #1
>
> The program must run under DOS environment.
> Thank you for your time, and any help would be greatly appreciated.
>
> shin@seas.ucla.edu
Microsoft put serial drivers in their versions of BASIC, which was
a nice thing to do. Then, they pretty much left them out of the
O/S, which wasn't nice. So you really can't do a direct translation
of this QBASIC code into C or C++. (Note: they put the serial drivers
into MS Windows, so you can do this translation, sort of. The rest
of this message applies to MS-DOS only.)
To talk to the serial ports, particularly for input, you are going to
need a set of routines that perform interrupt driven communications.
You can buy a commercial library, find a shareware library, or just
pull some code into your program.
If you just want some simple code to add to your program, you can find
it accompanying a magazine article on my home page. Follow the links
to Articles and look for "Servicing COM Port Interrupts", which ran
in 1990.
If you want to know more, there is at least one other article on serial
communications there. You can also follow the links to my book, "Serial
Communications: A C++ Developer's Guide," if you want more depth.